package top.datacluster.basic.algorithm.leetcode.dynamic;

public class LeetCode983 {


    public int mincostTickets(int[] days, int[] costs) {
        int dp[] = new int[days.length];
        dp[0] = Math.min(Math.min(costs[0], costs[1]), costs[2]);
        int interval = 0;
        int result = 0;
        for (int i = 1; i < days.length; i++){
            interval += days[i] - days[i-1];
            if (interval > 29){
                result = dp[i - 1];
                int temp = Math.min(Math.min(costs[1] + result, costs[0] + dp[i-1]), costs[2] + result);
                dp[i] = Math.min(temp, costs[2]);
            }else{
                if (interval > 6){
                    result = dp[i - 1];
                    dp[i] = Math.min(Math.min(costs[0], costs[1]), costs[2]) + result;
                    interval = 0;
                }else{
                    dp[i] = Math.min((costs[2] + result), Math.min(costs[1] + result, costs[0] + dp[i-1]));

                }
            }

        }
        return dp[dp.length - 1];
    }



    public static void main(String[] args) {
//        int[] test = new int[]{1,4,6,9,10,11,12,13,14,15,16,17,18,20,21,22,23,27,28};
//        int[] cost = new int[]{3,13,45};
//        int[] test = new int[]{1,2,3,4,5,6,7,8,9,10,30,31};
//        int[] cost = new int[]{2,7,15};
//        int[] test = new int[]{1,4,6,7,8,20};
//        int[] cost = new int[]{7,2,15};
        int[] test = new int[]{4,5,9,11,14,16,17,19,21,22,24};
        int[] cost = new int[]{1,4,18};
        System.out.println(new LeetCode983().mincostTickets(test, cost));
    }
}
